<?php
  /**
   * @author tuannguyen2042
   * @copyright 2014
   * 
   */ 
?>

<?php
//var_dump($locIds);
//var_dump($catIds);
?>

<table cellspacing="0" cellpadding="0" width="100%">
    <?php
    $i = 0;
    foreach($ListingsTags as $item){
      $class = null;
      if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
      }
      
      foreach($item['Listing'] as $listing ){
        if(isset($listing)){
    ?>
  
    <tr<?php echo $class; ?>>
      <td valign="top" style="padding-right: 5px; width: 125px;">
        <div class="preview" style="margin-bottom: 10px;">
          <img src="http://open.thumbshots.org/image.pxf?url=<?php echo urlencode($listing["url"]); ?>" alt="<?php echo htmlspecialchars($listing["url"]); ?>" />
        </div>
      </td>
      <td valign="top" style="padding-right: 5px;">
        <div class="title">
          <?php echo '<a href="' . SITE_WEBROOT . $listing["url_title"] . '-l' . $listing["id"] . '.html">' . htmlspecialchars($listing["title"]) . '</a>'; ?>
        </div>
        <div class="url"><?php echo htmlspecialchars($listing["url"]); ?></div>
        <p>
        <?php
          echo $htmlToText->html2text($listing["description"], 160, true);
          echo '</p>';
                       
          $ts = explode('<br/>',$listing['Listing'][0]['train_stations']);
          $bs = explode('<br/>',$listing['Listing'][0]['bus_stations']);
          $ss = explode('<br/>',$listing['Listing'][0]['subway_stations']);
        ?>
        
        <!--  <strong>Distance:</strong><div><?php echo round($listing[0]['distance'])?> m<div>-->
        <?php if (($ts[0]!=='')){ ?>
        <strong>Train Station</strong>
        <div><?php echo $ts[0]; } ?></div>
        
        <?php if (($bs[0]!=='')){ ?>
        <strong>Bus Station</strong>
        <div><?php echo $bs[0];}?></div>
        
        <?php if (($ss[0]!=='')){ ?>
        <strong>Subway Station</strong>
        <div><?php echo $ss[0]; } ?></div>            
      </td>
    </tr>
    <?php  
       }
      }
    }
  
    foreach ($Listings as $listing) {
      $class = null;
      if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
      }
    ?>
    
    <tr<?php echo $class; ?>>
      <td valign="top" style="padding-right: 5px; width: 125px;">
        <div class="preview" style="margin-bottom: 10px;">
          <img src="http://open.thumbshots.org/image.pxf?url=<?php echo urlencode($listing["Listing"]["url"]); ?>" alt="<?php echo htmlspecialchars($listing["Listing"]["url"]); ?>" />
        </div>
      </td>
      <td valign="top" style="padding-right: 5px;">
        <div class="title">
          <?php echo '<a href="' . SITE_WEBROOT . $listing["Listing"]["url_title"] . '-l' . $listing["Listing"]["id"] . '.html">' . htmlspecialchars($listing["Listing"]["title"]) . '</a>'; ?>
        </div>
        <div class="url"><?php echo htmlspecialchars($listing["Listing"]["url"]); ?></div>
        <p>
          <?php
          echo $htmlToText->html2text($listing["Listing"]["description"], 160, true);
          echo '</p>';
                       
          $ts = explode('<br/>',$listing['Listing']['train_stations']);
          $bs = explode('<br/>',$listing['Listing']['bus_stations']);
          $ss = explode('<br/>',$listing['Listing']['subway_stations']);
          ?>
                    
          <?php if (($ts[0]!=='')){?>
          <strong>Train Station</strong>
          <div><?php echo $ts[0];}?></div>
          <?php if (($bs[0]!=='')){?>
          <strong>Bus Station</strong>
          <div><?php echo $bs[0];}?></div>
          <?php if (($ss[0]!=='')){?>
          <strong>Subway Station</strong>
          <div><? echo $ss[0];}?></div>
      </td>
    </tr>
    <?php } ?>
</table>

<?php echo $this->element('sql_dump'); ?>